//
//  ZYXPlayVC.m
//  RuiBeiKang
//
//  Created by iOS开发1 on 2019/1/29.
//  Copyright © 2019年 JW. All rights reserved.
//

#import "ZYXPlayVC.h"
#import "SelVideoPlayer.h"
#import "SelPlayerConfiguration.h"
#import "AppDelegate.h"
#import <Masonry/Masonry.h>

#import "ZYXClassNameModel.h"

@interface ZYXPlayVC ()
@property (nonatomic, strong) SelVideoPlayer *player;
@property (nonatomic, strong) SelPlayerConfiguration *configuration;
@property (strong,nonatomic) UIImageView *backImgview;
@property (strong,nonatomic) NSString *typeStr;
@end

@implementation ZYXPlayVC

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.title = @"视频或音频播放";
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    if ([[UIDevice currentDevice].systemVersion floatValue] > 7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    //保存路径需要转换为url路径，才能播放
    NSLog(@"self.playerItem.savePath =%@",self.playerItem.savePath);

    NSURL *url = [NSURL fileURLWithPath:self.playerItem.savePath];
    NSLog(@"videoUrl:%@", url);
    self.typeStr = [self.playerItem.savePath substringWithRange:NSMakeRange(self.playerItem.savePath.length -3, 3)];
    self.configuration = [[SelPlayerConfiguration alloc]init];
    self.configuration.shouldAutoPlay = YES;     //自动播放
    self.configuration.supportedDoubleTap = YES;     //支持双击播放暂停
    self.configuration.shouldAutorotate = YES;   //自动旋转
    self.configuration.repeatPlay = NO;     //重复播放
    self.configuration.statusBarHideState = SelStatusBarHideStateNever;     //设置状态栏隐藏
    self.configuration.sourceUrl = [NSURL fileURLWithPath:self.playerItem.savePath];     //设置播放数据源
    self.configuration.videoGravity = SelVideoGravityResize;   //拉伸方式
    self.backImgview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,250)];
    self.backImgview.image = [UIImage imageNamed:@"mp3fengmian"];
    self.backImgview.userInteractionEnabled = YES;
     _player = [[SelVideoPlayer alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,250) configuration:self.configuration  withType:self.typeStr ];
    if ([self.typeStr isEqualToString:@"mp4"]) {
        [self.view addSubview:_player];
    }else{
        [self.view addSubview:self.backImgview];
        [self.backImgview addSubview:_player];
    }
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [_player _deallocPlayer];
}


@end
